<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class LibArchive {
	var $starttime;
	var $endtime;
	
	//constructor
	function LibArchive() {
		
	}
	
	//methods
	function setStarttime($starttime) {
		$this->starttime['time'] = $starttime;
	}
	
	function setCountEnabled() {
		
	}
	
	function setCountDisabled() {
		
	}
	
	function get() {
		$list = $this->_get_list();
		
		return $list;
	}
	
	//private
	function _parse_time() {
		$time = $this->starttime['time'];
		if( strlen($time) > 10 ) {
			$this->starttime['year'] = substr($time, 0, 4);
			$this->starttime['month'] = substr($time, 5, 2);
			$this->starttime['day'] = substr($time, 8, 2);
		} else {
			$time = strftime("%Y-%m-%d %H:%M:%S", time() - 3600 * 21 * 30);
			$this->starttime['time'] = $time;
			$this->starttime['year'] = substr($time, 0, 4);
			$this->starttime['month'] = substr($time, 5, 2);
			$this->starttime['day'] = substr($time, 8, 2);
		}
		//
		if( $this->endtime == "" ) {
			$time = strftime("%Y-%m-%d %H:%M:%S", time());
			$this->endtime['time'] = $time;
			$this->endtime['year'] = substr($time, 0, 4);
			$this->endtime['month'] = substr($time, 5, 2);
			$this->endtime['day'] = substr($time, 8, 2);
		} else {
			$time = $this->endtime['time'];
			if( strlen($time) > 10 ) {
				$this->endtime['year'] = substr($time, 0, 4);
				$this->endtime['month'] = substr($time, 5, 2);
				$this->endtime['day'] = substr($time, 8, 2);
			}
		}
	}
	
	function _get_list() {
		$this->_parse_time();
		
		$list = array();
		$total = ($this->endtime['year'] - $this->starttime['year']) * 12 + (intval($this->endtime['month']) - intval($this->starttime['month']));
		for($i=$total; $i>=0; $i--) {
			$month = intval($this->starttime['month']) + $i;
			$year = intval($this->starttime['year']);
			$list[] = array('time' => strftime("%Y%m", mktime(0, 0, 0, $month, 1, $year)), 'text' => strftime("%b-%Y", mktime(0, 0, 0, $month, 1, $year)));
		}
		
		return $list;
	}
}
//
?>